
/**
1 压缩
2 转义
3 压缩转义
*/
function yasuo(ii) {
	var txtA = document.getElementById("json_input");
	var text = txtA.value;
	if (ii == 1 || ii == 3) {
		text = text.split("\n").join(" ");
		var t = [];
		var inString = false;
		for (var i = 0, len = text.length; i < len; i++) {
			var c = text.charAt(i);
			if (inString && c === inString) {
				// TODO: \\"
				if (text.charAt(i - 1) !== '\\') {
					inString = false;
				}
			} else if (!inString && (c === '"' || c === "'")) {
				inString = c;
			} else if (!inString && (c === ' ' || c === "\t")) {
				c = '';
			}
			t.push(c);
		}
		text = t.join('');
	}
	if (ii == 2 || ii == 3) {
		text = text.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"");
	}
	if (ii == 4) {
		text = text.replace(/\\\\/g, "\\").replace(/\\\"/g, '\"');
	}
	txtA.value = text;
}

String.prototype.trim = function () {
	return this.replace(/(^\s*)|(\s*$)/g, '');
}
var GB2312UnicodeConverter = {
	ToUnicode: function (str) {
		var txt = escape(str).replace(/%u/gi, '\\u');
		//var txt= escape(str).replace(/([%3F]+)/gi,'\\u');
		return txt.replace(/%7b/gi, '{').replace(/%7d/gi, '}').replace(/%3a/gi, ':').replace(/%2c/gi, ',').replace(/%27/gi, '\'').replace(/%22/gi, '"').replace(/%5b/gi, '[').replace(/%5d/gi, ']').replace(/%3D/gi, '=').replace(/%20/gi, ' ').replace(/%3E/gi, '>').replace(/%3C/gi, '<').replace(/%3F/gi, '?');//
	}
	, ToGB2312: function (str) {
		return unescape(str.replace(/\\u/gi, '%u'));
	}
};

function u2h() {
	var txtA = document.getElementById("json_input");
	var text = txtA.value;
	text = text.trim();
	// text = text.replace(/\u/g,"");
	txtA.value = GB2312UnicodeConverter.ToGB2312(text);
}

function h2u() {
	var txtA = document.getElementById("json_input");
	var text = txtA.value;
	text = text.trim();
	// text = text.replace(/\u/g,"");
	txtA.value = GB2312UnicodeConverter.ToUnicode(text);
}

function cnChar2EnChar() {
	var txtA = document.getElementById("json_input");
	var str = txtA.value;
	str = str.replace(/\’|\‘/g, "'").replace(/\“|\”/g, "\"");
	str = str.replace(/\【/g, "[").replace(/\】/g, "]").replace(/\｛/g, "{").replace(/\｝/g, "}");
	str = str.replace(/，/g, ",").replace(/：/g, ":");
	txtA.value = str;
}
